<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Actions\Grid;

use App\Models\OrderBeanRewards;
use App\Models\UserBeanPackages;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;

class DailyBeanOrderInfo extends LazyRenderable
{
    use LazyWidget;

    public function grid(): Grid
    {
        $id = $this->payload['id'];
        $type = $this->payload['type'];
        if ($type == UserBeanPackages::class) {
            $model = UserBeanPackages::with(['package', 'user'])->where('id', $id);
            return $this->getUserBeanPackagesGrid($model);
        }
        $model = OrderBeanRewards::with(['user', 'order' => function ($q) {
            $q->with(['productBrief', 'session']);
        }])->where('id', $id);
        return $this->getOrderBeanGrid($model);
    }

    public function getUserBeanPackagesGrid($model): Grid
    {
        return Grid::make($model, function (Grid $grid) {
            $grid->column('user.name', '用户名');
            $grid->column('user.flag', '用户标签');
            $grid->column('user.flag', '用户标签');
            $grid->column('user.telephone', '用户电话');
            $grid->column('package.name', '礼包名称');
            $grid->column('package.total_days', '礼包释放天数');
            $grid->column('total_beans', '礼包总KC通证');
            $grid->column('daily_release_rate', '释放百分比');
            $grid->column('purchase_amount', '购买金额');
            $grid->column('release_days', '剩余释放天数');
        });
    }

    public function getOrderBeanGrid($model): Grid
    {
        return Grid::make($model, function (Grid $grid) {
            $grid->column('user.name', '用户名');
            $grid->column('user.flag', '用户标签');
            $grid->column('user.telephone', '用户电话');
            $grid->column('order.session.date', '场次日期');
            $grid->column('order.session.name', '场次名称');
            $grid->column('order.productBrief.name', '商品名称');
            $grid->column('total_reward_beans', '总奖励KC通证');
            $grid->column('daily_release_rate', '每日释放百分比');
            $grid->column('released_days', '已释放天数');
            $grid->column('remaining_beans', '剩余待释放KC通证');
        });
    }
}
